package scenic.toolkit.text;

import java.awt.geom.Point2D;
import java.util.Vector;

import scenic.SceneContainer;
import scenic.toolkit.CComponent;

public class InlineComponent extends Element {
	CComponent component;
	
	public InlineComponent(CComponent component) {
		this.component = component;
	}
	
	@Override
	public CComponent getComponent() {
		return component;
	}
	
	@Override
	public int getNumItems() {
		return 1;
	}

	@Override
	public ElementItem getItemInfo(int index, ElementItem item) {
		Point2D size = component.getMinimumSize();
		
		if(item == null)
			item = new ElementItem();
		item.width = size.getX();
		item.ascent = size.getY();
		item.descent = 0.0;
		item.isSpace = false;
		item.element = this;
		item.index = 0;
		
		return item;
	}

	@Override
	public void drawObjects(SceneContainer scene, Vector<ElementItem> objects) {
		ElementItem item = objects.elementAt(0);
		
//		System.out.println("item " + item.x + " " + item.y + " " + item.width + " " + (item.ascent + item.descent));
		
		component.setPosition(item.x, item.y - item.ascent, item.width, item.ascent + item.descent);
		scene.add(component.getScene());
	}
}
